/**
 * Created by IntelliJ IDEA.
 * Time: 0:16
 *
 * @Author: xyb
 * @Version: 2017/6/30
 * To change this template use File | Settings | File Templates.
 */
package blog.web.message;


import blog.sys.data.message.MsgIndexInfo;
import blog.sys.entity.ChatMsg;
import blog.sys.entity.User;
import blog.sys.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import pub.spring.web.mvc.ActionResult;

import java.io.UnsupportedEncodingException;
import java.util.List;

@Controller
public class MainController {

    /**
     * 获取用户的好友列表与他的最新聊天记录
     *
     * @param userId
     * @return
     * @throws UnsupportedEncodingException
     */
    @RequestMapping
    public ActionResult getUserFriends(Integer userId) throws UnsupportedEncodingException {
        List<MsgIndexInfo> users = messageService.getUserFriends(userId);
        ActionResult result = ActionResult.ok();
        result.setData(users);
        return result;
    }

    /**
     * 获取与当前好友的聊天记录
     * 使用分页
     *
     * @param userId 当前用户id
     * @param toUserId 好友id
     * @param pageNum  显示当前页的聊天记录，默认是一页显示十条记录
     * @return
     * @throws UnsupportedEncodingException
     */
    @RequestMapping
    public ActionResult onShowCurrChatMsg(Integer userId, Integer toUserId,Integer pageNum) throws UnsupportedEncodingException {
        List<ChatMsg> msgs = messageService.onShowCurrChatMsg(userId, toUserId,pageNum);
        ActionResult result = ActionResult.ok();
        result.setData(msgs);
        return result;
    }

    @Autowired
    private MessageService messageService;

}
